//
//  ReplyTableViewCell.m
//  ShrimpCrowdordering
//
//  Created by 郑洲 on 2018/8/5.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "ReplyTableViewCell.h"

@interface ReplyTableViewCell ()

@property (nonatomic, strong) UIImageView *cheadView;
@property (nonatomic, strong) UILabel *cnameLabel;
@property (nonatomic, strong) UILabel *ccommentLabel;

@end

@implementation ReplyTableViewCell

+ (ReplyTableViewCell *)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"ReplyTableViewCell";
    ReplyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[ReplyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
        [cell createSubView];
    }
    
    return cell;
}

- (void)createSubView {
    self.bgView = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(48), 0, SCREEN_WIDTH - ScreenX375(64), ScreenX375(66))];
    self.bgView.backgroundColor = REXADECIMALCOLOR(@"#f6f6f6");
    [self addSubview:self.bgView];
    
    self.cheadView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(16), ScreenX375(24), ScreenX375(24))];
    self.cheadView.clipsToBounds = YES;
    self.cheadView.layer.cornerRadius = ScreenX375(12);
    self.cheadView.image = ImageWithName(@"头像2");
    [self.bgView addSubview:self.cheadView];
    
    self.cnameLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(46), ScreenX375(20), ScreenX375(150), ScreenX375(14))];
    self.cnameLabel.textColor = REXADECIMALCOLOR(@"#ababab");
    self.cnameLabel.font = Kfont(12);
    self.cnameLabel.text = @"饭饭";
    [self.bgView addSubview:self.cnameLabel];
    
    self.ccommentLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(46), ScreenX375(45), ScreenX375(200), ScreenX375(16))];
    self.ccommentLabel.textColor = REXADECIMALCOLOR(@"#1a1a1a");
    self.ccommentLabel.font = Kfont(12);
    self.ccommentLabel.numberOfLines = 0;
    self.ccommentLabel.text = @"嘿嘿~多谢支持";
    [self.bgView addSubview:self.ccommentLabel];
}

- (void)setCommentModel:(CommentModel *)commentModel {
    _commentModel = commentModel;
    if ([commentModel.userPic class] != [NSNull class]) {
        [self.cheadView sd_setImageWithURL:[NSURL URLWithString:commentModel.userPic] placeholderImage:nil options:SDWebImageRetryFailed];
    }
    self.cnameLabel.text = commentModel.userName;
    self.ccommentLabel.text = commentModel.content;
    CGFloat height = kGetStringHeight(commentModel.content, CGSizeMake(SCREEN_WIDTH - ScreenX375(128), MAXFLOAT), Kfont(12));
    self.ccommentLabel.frame = CGRectMake(ScreenX375(46), ScreenX375(45), SCREEN_WIDTH - ScreenX375(128), height + ScreenX375(2));
    self.bgView.frame = CGRectMake(ScreenX375(48), 0, SCREEN_WIDTH - ScreenX375(64), ScreenX375(62) + height);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
